﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace C12_Ex03_Shaked_032675316_Itay_032511057
{
    public class ImageWaterMarkDecorator : ImageFormaterDecorator
    {
        public const string k_WaterMarkString = "AutoStalk";
        public const string k_WaterMarkFontName = "David";
        public const int k_WaterMarkFontSize = 15;

        public ImageWaterMarkDecorator(ImageFormaterDecorator i_ImageStringFormatter) : base(i_ImageStringFormatter)
        {
        }

        public ImageWaterMarkDecorator()
            : base()
        {
        }

        private static Random s_Random = new Random();

        private static int getRandomIntFromRange(int i_Start, int i_End)
        {
            return s_Random.Next(i_Start, i_End);
        }
        
        public override Image FormatImage(Image i_Image)
        {
            i_Image = base.FormatImage(i_Image);

            Image tempImage = base.FormatImage(i_Image);
                        
            Graphics graphics = System.Drawing.Graphics.FromImage(tempImage);

            StringFormat strFormatter = new StringFormat();
            SolidBrush transBrush = new SolidBrush(Color.Blue);

            int x = getRandomIntFromRange(0, tempImage.Size.Width / 2 );
            int y = getRandomIntFromRange(0, tempImage.Size.Height / 2);
            Point stringLocation = new Point(x, y);

            graphics.DrawString(
                k_WaterMarkString, 
                new Font(k_WaterMarkFontName, k_WaterMarkFontSize),
                transBrush,
                stringLocation,
                strFormatter);

            Bitmap newImage = new Bitmap(tempImage);
            graphics = Graphics.FromImage(newImage);
            graphics.DrawImageUnscaled(tempImage, 0, 0);

            return (Image)newImage;
        }
    }
}
